package com.mxfcode.front.bbs_message.service.impl;

import com.mxfcode.bbs_common.date.DateUtils;
import com.mxfcode.common.HostHolder;
import com.mxfcode.entity.BBSMessage;
import com.mxfcode.entity.TSUser;
import com.mxfcode.front.bbs_message.mapper.MessageMapper;
import com.mxfcode.front.bbs_message.service.MessageService;
import com.mxfcode.front.dto.MessageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author moxiufeng
 * @date 2021/4/22 11:00
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;
    @Autowired
    private HostHolder hostHolder;
    @Override
    public int selectMessageRows(String userId) {
        return 0;
    }

    @Override
    public List<MessageDTO> selectMessageList() {
        return messageMapper.selectMessageList();
    }

    @Override
    public int addMessage(String content) {
        TSUser user = hostHolder.getUser();
        String userName = user == null ? null : user.getId();
        String realName = user == null ? null : user.getRealName();
        BBSMessage message = new BBSMessage();
        message.setCreateDate(DateUtils.getCurrentDateToDate());
        message.setCreateBy(userName);
        message.setCreateName(realName);
        message.setContent(content);
        message.setUserId(userName);
        return messageMapper.addMessage(message);
    }
}
